import axios from 'axios'
// 引入 NProgress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 新建一个axios实例
const request = axios.create({
  baseURL: '/wyyx',
  timeout: 10000
})

// 添加请求拦截器
request.interceptors.request.use(
  (config) => {
    // 开启进度条
    NProgress.start()
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 添加响应拦截器
request.interceptors.response.use(
  (response) => {
    // 隐藏进度条
    NProgress.done()
    return response.data
  },
  (error) => {
    // 隐藏进度条
    NProgress.done()
    return Promise.reject(error)
  }
)
export default request
